package com.smartscreen.lifeserviceinfomanage.service.impl;

import com.smartscreen.lifeserviceinfomanage.dto.CampusMapPoiDTO;
import com.smartscreen.lifeserviceinfomanage.entity.CampusMapPoi;
import com.smartscreen.lifeserviceinfomanage.mapper.CampusMapPoiMapper;
import com.smartscreen.lifeserviceinfomanage.service.CampusMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CampusMapServiceImpl implements CampusMapService {
    
    @Autowired
    private CampusMapPoiMapper campusMapPoiMapper;
    
    @Override
    public List<CampusMapPoiDTO> getAllPois() {
        List<CampusMapPoi> pois = campusMapPoiMapper.selectList(null);
        return pois.stream().map(this::convertToDTO).collect(Collectors.toList());
    }
    
    private CampusMapPoiDTO convertToDTO(CampusMapPoi poi) {
        CampusMapPoiDTO dto = new CampusMapPoiDTO();
        dto.setPoiId(poi.getPoiId());
        dto.setName(poi.getName());
        dto.setCategory(poi.getCategory());
        dto.setDescription(poi.getDescription());
        
        CampusMapPoiDTO.LocationDTO location = new CampusMapPoiDTO.LocationDTO();
        location.setLatitude(poi.getLatitude());
        location.setLongitude(poi.getLongitude());
        dto.setLocation(location);
        
        return dto;
    }
}